var xmlHttp;

function GetXmlHttpObject(){
var xmlHttp=null;
try{
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }catch (e){
 //Internet Explorer
        try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
 }
 if(xmlHttp==null){
		alert("errore, il tuo browser non supporta ajax");
		return;
	}
return xmlHttp;
}

function modificaClient(){

xmlHttp = GetXmlHttpObject();

	xmlHttp.onreadystatechange=function stateChanged2(){

			if(xmlHttp.readyState==4 && xmlHttp.status==200){
				
					document.getElementById("page").innerHTML=xmlHttp.responseText;
					
			}
			}
			xmlHttp.open("get","/IS/Controller/GestioneProfiloController/modifica.php",true);
			xmlHttp.send();



}
function salvaClient(vusername){


xmlHttp = GetXmlHttpObject();

var patternCF = /^[a-z]{6}[0-9]{2}[a-z][0-9]{2}[a-z][0-9]{3}[a-z]$/i;
var patternEmail= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;
var patternData= /^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[-/.](19|20)\d\d/;
var patternUser=/^[a-zA-Z]{4}[1-9]*$/;
var patternPass=/^[a-zA-Z0-9]{1,24}$/;
var patternNome=/^[a-zA-Z]{1,30}$/;

var username=document.getElementById("user").value;
var password=document.getElementById("password").value;
var nome=document.getElementById("nome").value;
var cognome=document.getElementById("cognome").value;
var cf=document.getElementById("cf").value;
var m=document.getElementById("M").checked;
var f=document.getElementById("F").checked;
var sesso;
if(m==true)
var sesso="M";
else
var sesso="F";
var data=document.getElementById("data").value;
var email=document.getElementById("email").value;


 if(cf.search(patternCF)==-1){
        alert("codice fiscale errato")
    }
 
    else if (data.search(patternData)==-1){
        alert("data errata")
    }
    else if (email.search(patternEmail)==-1){
        alert("formato email errato")
    }
    
    else if(username.search(patternUser)==-1){
        alert("username errato, quattro caratteri iniziali e poi numeri")
    }
    
    else if(password.search(patternPass)==-1){
        alert("Stringa alfanumerica di massimo 24 caratteri")
    }
    
    else if (nome.search(patternNome)==-1){
        alert("Il nome deve essere di minimo un carattere e massimo di trenta caratteri")
    }
    
    else if (cognome.search(patternNome)==-1){
        alert("Il cognome deve essere di minimo un carattere e massimo di trenta caratteri")
    }
        

    else {



	xmlHttp.onreadystatechange=function stateChanged4(){

			if(xmlHttp.readyState==4 && xmlHttp.status==200){
				
				document.getElementById("page").innerHTML=xmlHttp.responseText;
			}
			}
			
			xmlHttp.open("get","/IS/Controller/GestioneProfiloController/salva.php?&username="+username+"&password="+password+"&nome="+nome+"&cognome="+cognome+"&cf="+cf+"&sesso="+sesso+"&data="+data+"&email="+email+"&vusername="+vusername,true);
			xmlHttp.send();

}}
function openchat(){

   window.open("/IS/View/GestioneChatView/sample.php", "_blank");
					
					
}
			
	
function esciClient(){


window.location.assign("/IS/View/Homepage InfoHelp.html");
alert("Arrivederci");
}


function aggiornaClient(){
document.location.assign('/IS/View/Homepage_Cliente.html')
}


function resettaUtente(){
    
    
    document.getElementById("nome").value="";
    document.getElementById("cognome").value="";
    document.getElementById("cf").value="";
    document.getElementById("data").value="";
    document.getElementById("email").value="";
    document.getElementById("user").value="";
    document.getElementById("password").value="";
}
